stage.set_background("halfcourt")
sprite = codesters.Sprite("player4")
sprite.go_to(215, -175)
net = codesters.Sprite("basketballnet")
net.go_to(215, 175)
ball = codesters.Sprite("basketball")
x = random.randint(-100, 150)
ball.go_to(x, -25)
stage.set_gravity(10)
stage.set_bounce(.8)
ball.set_gravity_off()
net.set_gravity_off()
left_count = 0
down_count = 0
def left_key():
ball.move_left(10)
global left_count
left_count += 1
# add other actions...
stage.event_key("left", left_key)
def down_key():
ball.move_down(10)
global down_count
down_count += 1
# add other actions...
stage.event_key("down", down_key)
t = codesters.Teacher()
event = t.find_text('def')
grav = t.find_text('set_gravity_on')
handler = t.find_text('event_key')
try:
tval1 = event[2][1]
tval2 = event[2][0]
except:
tval1 = "DNE"
tval2 = "DNE"
try:
tval6 = handler[2][1]
tval7 = handler[2][0]
tval8 = t.get_indent_at_line(tval7)
except:
tval6 = "DNE"
tval7 = "DNE"
tval8 = "DNE"
try:
tval3 = grav[0][1]
tval4 = grav[0][0]
tval5 = t.get_indent_at_line(tval4)
except:
tval3 = "DNE"
tval4 = "DNE"
tval5 = "DNE"
try:
tval9 = t.find_text('jump')[0][1]
except:
tval9 = "DNE"
t1 = TestObjective()
t1.add_success('space_bar' in tval1 and '(sprite)' not in tval1, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add a Space Bar event?")
t1.add_failure('sprite' in tval1, "Oops! Did you add a Sprite Space Bar instead? Try looking in Stage Events.")
t1.add_failure('space_bar' not in tval1, "It looks like you added a different event. Try adding a Space Bar event.")
t1.add_failure(tval6 == "DNE", "Oops! Did you delete the last line of your Space Bar event?")
t1.add_failure(tval7 < tval4, "Make sure your Move Down command is inside your Space Bar event, after the first line and before the last.")
t1.add_failure(tval8 != 0, "Make sure the last line of your event is not indented at all.")
t2 = TestObjective()
t2.add_success('ball.' in tval3 and tval5 == 4 and tval4 > tval2, "Great job!")
t2.add_failure(tval3 == "DNE", "Did you add a Sprite Gravity On command to your event?")
t2.add_failure(tval9 != "DNE", "Did you remove the default jump command from your Space Bar event?")
t2.add_failure('ball.' not in tval3, "Did you change the name in front of the Sprite Gravity On command to ball?")
t2.add_failure('10' in tval3, "Make sure you use Sprite Gravity On, not Set Gravity.")
t2.add_failure(tval4 < tval2, "Make sure you place your Sprite Gravity On command after the first line of the Space Bar event.")
t2.add_failure(tval5 < 4, "Make sure your Sprite Gravity On command is indented 4 spaces inside the Space Bar event.")
t2.add_failure(tval5 > 4, "Oops, you indented too far. Make sure your Sprite Gravity On is 4 spaces inside your Space Bar event.")
tester = TestManager()
tester.add_test_list([t1, t2])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
提交作品
-
下个活动
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)